# print("dir\n\tsubdir1\n\t\tfile1.ext\n\t\tsubsubdir1\n\tsubdir2\n\t\tsubsubdir2\n\t\t\tfile2.ext".split("\n"))
# print("dir\n\tsubdir1\n\t\tfile1.ext\n\t\tsubsubdir1\n\tsubdir2\n\t\tsubsubdir2\n\t\t\tfile2.ext")
import re


class Solution:
    def lengthLongestPath(self, input: str) -> int:
        if not input:
            return 0
        if re.match(r".*?\.\w+", input):
            return len(input)
        file_list = input.split("\n")
        mid_list = [0] * len(file_list)
        mid_list[0] = len(file_list[0])
        res = 0
        for i in range(1, len(file_list)):
            text = file_list[i]
            count = text.count("\t")
            if re.match(r".*?\.\w+", text):
                res = max(res, mid_list[count-1] + len(text))
            else:
                mid_list[count] = mid_list[count-1] + len(text) - count
        return res


a = Solution()
print(a.lengthLongestPath("dir\n\tsubdir1\n\t\tfile1.ext\n\t\tsubsubdir1\n\tsubdir2\n\t\tsubsubdir2\n\t\t\tfile2.ext"))
